Posts

activerecord - Using method in a where clause Rails Ruby Active Record -

i wondering if posible use model instance method clause query. mean. have model school method defined class school < activerecord::base def my_method users.where(blablabla).present? end end is posible like: school.all.where(my_method: true) i know can like: school.all.map{|x| x if x.my_method} but way has huge penalization in performance compared query. furthermore, return of i'm searching activerecord relation , map returns array. update: also there way like: school.all.joins(:users).where("users.attribute = something") but not fit want several reasons. thanks in advance i don't know relations between models. but clause gets hash of key - value. can example return id's of users in kind of hash , use it. def my_method {user_id: users.where(blablabla).ids} end and use it: school.all.where(my_method)

mysql - SQL Join Between Two Tables -

below 2 tables structure, mysql> desc catalog_product_entity; +------------------+----------------------+------+-----+---------------------+----------------+ | field | type | null | key | default | | +------------------+----------------------+------+-----+---------------------+----------------+ | entity_id | int(10) unsigned | no | pri | null | auto_increment | | entity_type_id | smallint(8) unsigned | no | mul | 0 | | | attribute_set_id | smallint(5) unsigned | no | mul | 0 | | | type_id | varchar(32) | no | | simple | | | sku | varchar(64) | yes | mul | null | | | created_at | datetime | no | | 0000-00-00 00:00:00 | | | updated_at | datetime | no | | 0000-00-00 00:...

java - Join different tables determined by a control filed -

there 3 tables , b1 , b2: a(id, b_id, control) b1(id, other) b2(id, other) if control = 1, b_id in mapping table b1; if control = 2, b_id in mapping table b2. these 3 classes like: @entity @table(name = "a") public class { @id @column(name = "id") private integer id; private b b; @column(name = "control") private integer control; } @entity @table(name = "b1") public class b1 { @id @column(name = "id") private integer id; @column(name = "other") private integer other; } class b2 same b1. i need different object b table b1 or b2 determined field control in class a. possible make hibernate annotation? appreciated advice. i think missing out way 1 table refers in sql. mean way have defined tables there no foreign keys , no referential integrity secured. recommend reconsidering implementation , add respective foreign keys in table. anyway, if want contin...

sql server - SQL - parametrized procedure with multiple parameters as array -

i have simple procedure: create procedure [report] @statusvalue varchar(200) = '%' begin select * sometable upper(@statusvalue) end i'd provide user set multiple statusvalue. because there 6 levels of statusvalue in table, i'd provide user define required statusvalue procedure parameters - array. i don't know, how works - i'm new in area - i'm supposing have procedure one: exec report @statusvalue = 'statusvalue1|statusvalue2|statusvalue3' do happen know, how can adjust procedure have required output. many in advance. use following user defined function return values delimited string (say pipe): create function [dbo].[stringlist_to_table] (@list varchar(8000), @delimiter nchar(1) = n',') returns @tbl table (value varchar(8000)) begin declare @pos int, @tmpstr varchar(8000), @tmpval varchar(8000); set @tmpstr = @list; set @pos = charindex(@delimiter , @tmpstr); w...

Neo4j - Filter nodes by relationship attribute lists -

Image
lets have collections ( collection ) have things ( thing ) attached them. these collections can have sub collections contain subset of parent collection. there [:filters] relationship between parent , sub collection contain attribute lists thing s should filtered. attributes key same key on thing , , values key on relationship values accepted on thing . if relationship not have attributes, thing s should "shared" between collections. the problem i'm having hard time solving how filter things attributes on relationship. here graph like: graph view and here cypher code creating said graph: // collections create (c1:collection {name: 'c1'})-[:filters {type: ['image']}]->(c1_img:collection {name:'c1_img'}), (c1_img)-[:filters {user: ['john']}]->(c1_user_img:collection {name:'c1_user_img'}), (c2:collection {name: 'c2'})-[:filters {type: ['image']}]->(c2_img:collection {name:'c2_img'}), (c2_...

php - How to call API from frontend/backend application in Yii? -

so yii structure this. api |modules |v2 |actions common frontend backend we can call common in backend , frontend. able call backend modules in frontend module. is possible call api i.e v2 action frontend module in yii? this required done api module there. , avoiding backend logic need call api. you can use soa(service oriented architecture) in yii, have create services folder in service write logics can used backend , api's both frontend api based , backend service based. below api     |modules         |v2              |actions common frontend backend services

asp.net mvc - asp-validation-summary shows custom but not model errors -

asp-validation-summary in view shows errors added via modelstate.addmodelerror, don't show model validation errors ("the user field required."). i'm using microsoft.aspnetcore.mvc 1.0.0-rc2-final. btw: user field not displayed via view correctly identified ef model level error before add. //<div asp-validation-summary="modelonly" class="text-danger"></div> in view modelstate.addmodelerror(string.empty, "this error shows in validation-summary"); viewbag.headermessage = "error: " + string.join(" - ", modelstate.values.selectmany(x => x.errors).select(x => x.errormessage)); errors show in field filled via viewbag not in validation-summary change html: <div asp-validation-summary="modelonly" class="text-danger"></div> to <div asp-validation-summary="all" class="text-danger"></div>