class ConferenceSession < ActiveRecord::Base
has_many :conference_sessions
end
class ConferenceSession < ActiveRecord::Base
belongs_to :conference
has_and_belongs_to_many :users
end
class User < ActiveRecord::Base
has_and_belongs_to_many :conference_sessions
end
和conference_sesssions_users表。管理员可以允许特定人员参加特定会话。所以我想形成一个查询,每当用户登录并选择一个会议时,他应该只允许他看到管理员允许他访问的会话。
我已经通过执行此操作来完成特定会话
scope :visibility,
lambda { |user_id| joins('INNER JOIN conference_sessions_users
ON conference_sessions_users.conference_session_id = conference_sessions.id').
where('conference_sessions_users.user_id = ?', user_id) }
但这仅返回特定的人,如果会话对所有用户可见,该条件应该是什么呢。
答案 0 :(得分:0)
您可以将条件更改为import org.junit.Rule
import org.scalatest.FunSuite
import com.datastax.driver.core.ResultSet
import org.cassandraunit.CassandraCQLUnit
import org.cassandraunit.dataset.cql.ClassPathCQLDataSet
class CassandraTest extends FunSuite{
@Rule
val cassandraCQLUnit = new CassandraCQLUnit(new ClassPathCQLDataSet("statementsWithBlankEndings.cql", "mykeyspace"))
test("really simple transformation") {
val session = cassandraCQLUnit.session
val resultSet = session.execute("select * from testCQLTable WHERE id='1690e8da-5bf8-49e8-9583-4dff8a570737'")
println(resultSet.iterator().next().getString("value"))
}
}
java.lang.NullPointerException was thrown.
java.lang.NullPointerException
at CassandraTest$$anonfun$1.apply$mcV$sp(CassandraTest.scala:21)
at CassandraTest$$anonfun$1.apply(CassandraTest.scala:18)
at CassandraTest$$anonfun$1.apply(CassandraTest.scala:18)
at org.scalatest.OutcomeOf$class.outcomeOf(OutcomeOf.scala:85)
at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
at org.scalatest.Transformer.apply(Transformer.scala:22)
at org.scalatest.Transformer.apply(Transformer.scala:20)
at org.scalatest.FunSuiteLike$$anon$1.apply(FunSuiteLike.scala:186)
at org.scalatest.TestSuite$class.withFixture(TestSuite.scala:196)
at org.scalatest.FunSuite.withFixture(FunSuite.scala:1560)
at org.scalatest.FunSuiteLike$class.invokeWithFixture$1(FunSuiteLike.scala:183)
at org.scalatest.FunSuiteLike$$anonfun$runTest$1.apply(FunSuiteLike.scala:196)
at org.scalatest.FunSuiteLike$$anonfun$runTest$1.apply(FunSuiteLike.scala:196)
at org.scalatest.SuperEngine.runTestImpl(Engine.scala:289)
at org.scalatest.FunSuiteLike$class.runTest(FunSuiteLike.scala:196)
at org.scalatest.FunSuite.runTest(FunSuite.scala:1560)
at org.scalatest.FunSuiteLike$$anonfun$runTests$1.apply(FunSuiteLike.scala:229)
at org.scalatest.FunSuiteLike$$anonfun$runTests$1.apply(FunSuiteLike.scala:229)
at org.scalatest.SuperEngine$$anonfun$traverseSubNodes$1$1.apply(Engine.scala:396)
at org.scalatest.SuperEngine$$anonfun$traverseSubNodes$1$1.apply(Engine.scala:384)
at scala.collection.immutable.List.foreach(List.scala:381)
at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:384)
at org.scalatest.SuperEngine.org$scalatest$SuperEngine$$runTestsInBranch(Engine.scala:379)
at org.scalatest.SuperEngine.runTestsImpl(Engine.scala:461)
at org.scalatest.FunSuiteLike$class.runTests(FunSuiteLike.scala:229)
at org.scalatest.FunSuite.runTests(FunSuite.scala:1560)
at org.scalatest.Suite$class.run(Suite.scala:1147)
at org.scalatest.FunSuite.org$scalatest$FunSuiteLike$$super$run(FunSuite.scala:1560)
at org.scalatest.FunSuiteLike$$anonfun$run$1.apply(FunSuiteLike.scala:233)
at org.scalatest.FunSuiteLike$$anonfun$run$1.apply(FunSuiteLike.scala:233)
at org.scalatest.SuperEngine.runImpl(Engine.scala:521)
at org.scalatest.FunSuiteLike$class.run(FunSuiteLike.scala:233)
at org.scalatest.FunSuite.run(FunSuite.scala:1560)
at org.scalatest.tools.SuiteRunner.run(SuiteRunner.scala:45)
at org.scalatest.tools.Runner$$anonfun$doRunRunRunDaDoRunRun$1.apply(Runner.scala:1340)
at org.scalatest.tools.Runner$$anonfun$doRunRunRunDaDoRunRun$1.apply(Runner.scala:1334)
at scala.collection.immutable.List.foreach(List.scala:381)
at org.scalatest.tools.Runner$.doRunRunRunDaDoRunRun(Runner.scala:1334)
at org.scalatest.tools.Runner$$anonfun$runOptionallyWithPassFailReporter$2.apply(Runner.scala:1011)
at org.scalatest.tools.Runner$$anonfun$runOptionallyWithPassFailReporter$2.apply(Runner.scala:1010)
at org.scalatest.tools.Runner$.withClassLoaderAndDispatchReporter(Runner.scala:1500)
at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:1010)
at org.scalatest.tools.Runner$.run(Runner.scala:850)
at org.scalatest.tools.Runner.run(Runner.scala)
at org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.runScalaTest2(ScalaTestRunner.java:138)
at org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.main(ScalaTestRunner.java:28)
,这可能会转换为以下内容:where(conference_sessions_users: { user_id: user_ids})
。当然,在这种情况下,您应该将{id}数组传递为WHERE conference_sessions_users.user_id in (1st_id, 2nd_id)
答案 1 :(得分:0)